package com.ruoyi.nongjt.service.impl;

import com.ruoyi.nongjt.domain.dto.CertificateStatisticsDTO;
import com.ruoyi.nongjt.mapper.CertificateStatisticsMapper;
import com.ruoyi.nongjt.service.CertificateStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 合格证统计Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-01-01
 */
@Service
public class CertificateStatisticsServiceImpl implements CertificateStatisticsService 
{
    @Autowired
    private CertificateStatisticsMapper certificateStatisticsMapper;

    /**
     * 获取合格证统计概览数据
     */
    @Override
    public CertificateStatisticsDTO getStatisticsOverview(String districtCode, String year, String month)
    {
        CertificateStatisticsDTO dto = new CertificateStatisticsDTO();
        dto.setDistrictCode(districtCode);
        dto.setYear(year);
        dto.setMonth(month);
        
        // 获取各项统计数据
        dto.setMonthlyStatistics(getMonthlyStatistics(districtCode, year));
        dto.setProductStatistics(getProductStatistics(districtCode, year, month));
        dto.setStreetStatistics(getStreetStatistics(districtCode, year));
        dto.setEntityStatistics(getEntityStatistics(districtCode, year));
        dto.setStreetUserStatistics(getStreetUserStatistics(districtCode, year));
        dto.setDailyStatistics(getDailyStatistics(districtCode, year, month));
        
        return dto;
    }

    /**
     * 获取合格证开具数量统计（按月）
     */
    @Override
    public List<CertificateStatisticsDTO.MonthlyStatistics> getMonthlyStatistics(String districtCode, String year)
    {
        return certificateStatisticsMapper.selectMonthlyStatistics(districtCode, year);
    }

    /**
     * 获取主要农产品数量统计
     */
    @Override
    public List<CertificateStatisticsDTO.ProductStatistics> getProductStatistics(String districtCode, String year, String month)
    {
        return certificateStatisticsMapper.selectProductStatistics(districtCode, year, month);
    }

    /**
     * 获取街道/镇合格证打印数量统计
     */
    @Override
    public List<CertificateStatisticsDTO.StreetStatistics> getStreetStatistics(String districtCode, String year)
    {
        return certificateStatisticsMapper.selectStreetStatistics(districtCode, year);
    }

    /**
     * 获取主体合格证开具数量排名
     */
    @Override
    public List<CertificateStatisticsDTO.EntityStatistics> getEntityStatistics(String districtCode, String year)
    {
        return certificateStatisticsMapper.selectEntityStatistics(districtCode, year);
    }

    /**
     * 获取街道/镇用户数量统计
     */
    @Override
    public List<CertificateStatisticsDTO.StreetUserStatistics> getStreetUserStatistics(String districtCode, String year)
    {
        return certificateStatisticsMapper.selectStreetUserStatistics(districtCode, year);
    }

    /**
     * 获取每日合格证开具实时数据
     */
    @Override
    public List<CertificateStatisticsDTO.DailyStatistics> getDailyStatistics(String districtCode, String year, String month)
    {
        return certificateStatisticsMapper.selectDailyStatistics(districtCode, year, month);
    }
}
